package com.strato.jdbc.datasource.v1_0_0;

import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;

public class DefaultDataSourceFactory implements DataSourceFactory {

	private Map<String,DataSource> datasources=new HashMap<String,DataSource>();
	
	@Override
	public DataSource getDataSource(String name) {
		DataSource ds=datasources.get(name);
		if(ds==null){
			return null;
		}
		if(DynamicDataSource.class.isInstance(ds)){
			DynamicDataSource dds=(DynamicDataSource) ds;
			ds=dds.getDyamicDataSource();
		}
		return ds;
	}

	@Override
	public void setDataSource(String name, DataSource dataSource) {
		datasources.put(name, dataSource);
	}

	@Override
	public DataSource removeDataSource(String name) {
		return datasources.remove(name);
	}

	@Override
	public void destroy() {
	}

	@Override
	public Map<String, DataSource> getDatasources() {
		return datasources;
	}

}
